/*Prints the elements of a linked list of integers.*/

object LinkedListExample  {
	def main() : Unit = { 
		println((new test1()).realMain());
	}
}

class test1{

	def realMain() : String = {
		var node1 : LinkedList;
		var node2 : LinkedList;
		var node3 : LinkedList;
		var trash : Int;

		node1 = new LinkedList();
		node2 = new LinkedList();
		node3 = new LinkedList();

		trash = node1.setElem(1);
		trash = node2.setElem(2);
		trash = node3.setElem(3);

		trash = node1.setNext(node2);
		trash =	node2.setNext(node3);
		
		trash = node1.printList();

		return "done";
	}
}




/*Linked list of integers.*/

class LinkedList {
	var element : Int;
	var next : LinkedList;
	var nextExists : Bool;	

	def setNext( nextArg : LinkedList) : Int = { 
		next = nextArg;
		nextExists = true;
		return 0;
	}


	def getNextExists() : Bool = {return nextExists;}
	def getElem() : Int = { return element; }
	def getNext() : LinkedList = { return next;}

	def setElem( other : Int ) : Int = {
		element = other;
		return 0;
	}

	def printList () : Int = {
		var current : LinkedList;
		current = this;		
		
		while ( current.getNextExists() ){	
			println(current.getElem());
			current = current.getNext();			
		}
		println(current.getElem());
		

		return 0;	
		
	}

}
